{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "38d33391",
   "metadata": {},
   "source": [
    "# `stroke` aesthetic\n",
    "\n",
    "Affects the thickness of the point boundaries (in case the given shape has a boundary).\n",
    "\n",
    "Available for the following geometries: `geomPoint()`, `geomJitter()`, `geomQQ()`, `geomQQ2()`, `geomPointRange()`, `geomDotplot()`, `geomYDotplot()`."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2414e10d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"2ti0Ie\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"library\">\n",
       "       if(!window.letsPlotCallQueue) {\n",
       "           window.letsPlotCallQueue = [];\n",
       "       }; \n",
       "       window.letsPlotCall = function(f) {\n",
       "           window.letsPlotCallQueue.push(f);\n",
       "       };\n",
       "       (function() {\n",
       "           var script = document.createElement(\"script\");\n",
       "           script.type = \"text/javascript\";\n",
       "           script.src = \"https://cdn.jsdelivr.net/gh/JetBrains/lets-plot@v3.2.0/js-package/distr/lets-plot.min.js\";\n",
       "           script.onload = function() {\n",
       "               window.letsPlotCall = function(f) {f();};\n",
       "               window.letsPlotCallQueue.forEach(function(f) {f();});\n",
       "               window.letsPlotCallQueue = [];\n",
       "               \n",
       "               \n",
       "           };\n",
       "           script.onerror = function(event) {\n",
       "               window.letsPlotCall = function(f) {};\n",
       "               window.letsPlotCallQueue = [];\n",
       "               var div = document.createElement(\"div\");\n",
       "               div.style.color = 'darkred';\n",
       "               div.textContent = 'Error loading Lets-Plot JS';\n",
       "               document.getElementById(\"2ti0Ie\").appendChild(div);\n",
       "           };\n",
       "           var e = document.getElementById(\"2ti0Ie\");\n",
       "           e.appendChild(script);\n",
       "       })();\n",
       "   </script>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "%useLatestDescriptors\n",
    "%use lets-plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "49a95a58",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Lets-Plot Kotlin API v.4.4.0. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.3.2.0."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "LetsPlot.getInfo()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "7795fa94",
   "metadata": {},
   "outputs": [],
   "source": [
    "val n = 26\n",
    "val data1 = mapOf(\n",
    "    \"x\" to List(4) { (0..6) }.flatten().take(n),\n",
    "    \"y\" to (3 downTo 0).flatMap { y -> List(7) { y } }.take(n),\n",
    "    \"shape\" to (0 until n).toList()\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "1b7975fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "val p1 = letsPlot(data1) { x = \"x\"; y = \"y\" } + \n",
    "        scaleShapeIdentity() + \n",
    "        lims(x = -1 to 7, y = -1 to 4) +\n",
    "        theme().legendPositionNone()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "788ed3dd",
   "metadata": {},
   "source": [
    "#### 1. Default Stroke"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "fbbf5d7f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"H0ymgh\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"shape\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0],\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,0.0,1.0,2.0,3.0,4.0],\n",
       "\"y\":[3.0,3.0,3.0,3.0,3.0,3.0,3.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"shape\",\n",
       "\"discrete\":true,\n",
       "\"scale_mapper_kind\":\"identity\",\n",
       "\"guide\":\"none\"\n",
       "},{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-1.0,7.0]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"limits\":[-1.0,4.0]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"shape\":\"shape\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"#54278f\",\n",
       "\"size\":12.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"fill\":\"#dd1c77\",\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"H0ymgh\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p1 + geomPoint(size=12, color=\"#54278f\", fill=\"#dd1c77\") { shape = \"shape\" }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ec91cc9b",
   "metadata": {},
   "source": [
    "#### 2. Increased Stroke"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "57c5e75c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"w1Hfku\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"shape\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0,11.0,12.0,13.0,14.0,15.0,16.0,17.0,18.0,19.0,20.0,21.0,22.0,23.0,24.0,25.0],\n",
       "\"x\":[0.0,1.0,2.0,3.0,4.0,5.0,6.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,0.0,1.0,2.0,3.0,4.0,5.0,6.0,0.0,1.0,2.0,3.0,4.0],\n",
       "\"y\":[3.0,3.0,3.0,3.0,3.0,3.0,3.0,2.0,2.0,2.0,2.0,2.0,2.0,2.0,1.0,1.0,1.0,1.0,1.0,1.0,1.0,0.0,0.0,0.0,0.0,0.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"shape\",\n",
       "\"discrete\":true,\n",
       "\"scale_mapper_kind\":\"identity\",\n",
       "\"guide\":\"none\"\n",
       "},{\n",
       "\"aesthetic\":\"x\",\n",
       "\"limits\":[-1.0,7.0]\n",
       "},{\n",
       "\"aesthetic\":\"y\",\n",
       "\"limits\":[-1.0,4.0]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"shape\":\"shape\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"#54278f\",\n",
       "\"size\":12.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"fill\":\"#dd1c77\",\n",
       "\"stroke\":8.0,\n",
       "\"data\":{\n",
       "}\n",
       "}],\n",
       "\"theme\":{\n",
       "\"legend_position\":\"none\"\n",
       "}\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"w1Hfku\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "p1 + geomPoint(size=12, stroke=8, color=\"#54278f\", fill=\"#dd1c77\") { shape = \"shape\" }"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a80e77a8",
   "metadata": {},
   "source": [
    "#### 3. Stroke Scales"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "cd516883",
   "metadata": {},
   "outputs": [],
   "source": [
    "val data2 = mapOf(\n",
    "    \"x\" to listOf(0, 1, 2),\n",
    "    \"y\" to listOf(0, 0, 0),\n",
    "    \"stroke\" to listOf(4, 16, 8)\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "65ac3c1e",
   "metadata": {},
   "outputs": [],
   "source": [
    "val p2 = letsPlot(data2) { x = \"x\"; y = \"y\" } +\n",
    "    geomPoint(size = 12, shape = 21, color = \"#54278f\", fill = \"#dd1c77\") { stroke = \"stroke\" }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "86c86e91",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "   <div id=\"2VDODe\"></div>\n",
       "   <script type=\"text/javascript\" data-lets-plot-script=\"plot\">\n",
       "       (function() {\n",
       "           var plotSpec={\n",
       "\"layout\":{\n",
       "\"name\":\"grid\",\n",
       "\"ncol\":2,\n",
       "\"nrow\":2,\n",
       "\"fit\":true,\n",
       "\"align\":false\n",
       "},\n",
       "\"figures\":[{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"Default scale\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0],\n",
       "\"y\":[0.0,0.0,0.0],\n",
       "\"stroke\":[4.0,16.0,8.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"stroke\":\"stroke\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"#54278f\",\n",
       "\"shape\":21.0,\n",
       "\"size\":12.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"fill\":\"#dd1c77\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"scaleStroke()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0],\n",
       "\"y\":[0.0,0.0,0.0],\n",
       "\"stroke\":[4.0,16.0,8.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"stroke\",\n",
       "\"range\":[2.0,4.0]\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"stroke\":\"stroke\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"#54278f\",\n",
       "\"shape\":21.0,\n",
       "\"size\":12.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"fill\":\"#dd1c77\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},{\n",
       "\"ggtitle\":{\n",
       "\"text\":\"scaleStrokeIdentity()\"\n",
       "},\n",
       "\"mapping\":{\n",
       "\"x\":\"x\",\n",
       "\"y\":\"y\"\n",
       "},\n",
       "\"data\":{\n",
       "\"x\":[0.0,1.0,2.0],\n",
       "\"y\":[0.0,0.0,0.0],\n",
       "\"stroke\":[4.0,16.0,8.0]\n",
       "},\n",
       "\"kind\":\"plot\",\n",
       "\"scales\":[{\n",
       "\"aesthetic\":\"stroke\",\n",
       "\"scale_mapper_kind\":\"identity\",\n",
       "\"guide\":\"none\"\n",
       "}],\n",
       "\"layers\":[{\n",
       "\"mapping\":{\n",
       "\"stroke\":\"stroke\"\n",
       "},\n",
       "\"stat\":\"identity\",\n",
       "\"color\":\"#54278f\",\n",
       "\"shape\":21.0,\n",
       "\"size\":12.0,\n",
       "\"position\":\"identity\",\n",
       "\"geom\":\"point\",\n",
       "\"fill\":\"#dd1c77\",\n",
       "\"data\":{\n",
       "}\n",
       "}]\n",
       "},\"blank\"],\n",
       "\"kind\":\"subplots\"\n",
       "};\n",
       "           var plotContainer = document.getElementById(\"2VDODe\");\n",
       "           window.letsPlotCall(function() {{\n",
       "               LetsPlot.buildPlotFromProcessedSpecs(plotSpec, -1, -1, plotContainer);\n",
       "           }});\n",
       "       })();    \n",
       "   </script>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "gggrid(\n",
    "    listOf(\n",
    "        p2 + ggtitle(\"Default scale\"),\n",
    "        p2 + scaleStroke(range = 2 to 4) + ggtitle(\"scaleStroke()\"),\n",
    "        p2 + scaleStrokeIdentity() + ggtitle(\"scaleStrokeIdentity()\"),\n",
    "    ),\n",
    "    ncol = 2\n",
    ")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Kotlin",
   "language": "kotlin",
   "name": "kotlin"
  },
  "language_info": {
   "codemirror_mode": "text/x-kotlin",
   "file_extension": ".kt",
   "mimetype": "text/x-kotlin",
   "name": "kotlin",
   "nbconvert_exporter": "",
   "pygments_lexer": "kotlin",
   "version": "1.8.20"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
